﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.Controls
{
    public partial class MainLeft : System.Web.UI.UserControl
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            
            int parentCategory = int.Parse(Request.QueryString["parentCategory"]);

            if (parentCategory == 0)
            {
                int category = int.Parse(Request.QueryString["categories"]);
                rep_subItem.DataSource = db.SubMenu.Where(s => s.ParentCategory == category).OrderBy(s => s.MOrder);
            }
            else 
            {
                rep_subItem.DataSource = db.SubMenu.Where(s => s.ParentCategory == parentCategory).OrderBy(s => s.MOrder);
            }
            
            rep_subItem.DataBind();

            hotlineImg.Visible = parentCategory == 33;
        }

        protected void rep_subItem_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink hl = (HyperLink)e.Item.FindControl("hl");
                var item = (SubMenu)e.Item.DataItem;

                hl.Text = item.Name;
                hl.NavigateUrl = item.UrlRewrite;
                /*switch (item.Categories)
                { 
                    case 50:
                        hl.NavigateUrl = "/WebPages/School/Introduction.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 1:
                        hl.NavigateUrl = "/WebPages/School/LeaderList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 49:
                        hl.NavigateUrl = "/WebPages/School/ExLeaderList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 2:
                        hl.NavigateUrl = "/WebPages/School/TeacherList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 4:
                        hl.NavigateUrl = "/WebPages/TeacheManage/SubList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 7:
                        hl.NavigateUrl = "/WebPages/Research/Platform.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 18:
                        hl.NavigateUrl = "/WebPages/Teacher/LadyDeeds.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 20:
                        hl.NavigateUrl = "/WebPages/Download/DownloadList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 21:
                        hl.NavigateUrl = "/WebPages/Download/DownloadList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    case 22:
                        hl.NavigateUrl = "/WebPages/Download/DownloadList.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                    default:
                        hl.NavigateUrl = "/WebPages/List.aspx?parentCategory=" + item.ParentCategory.ToString() + "&categories=" + item.Categories.ToString();
                        break;
                } */               
            }
        }
    }
}